define(["jquery"], function () {
    var timer = null;
    var clientHeight = $(window).height();
    let arrayList=null;
    function lazyLoad(selector) {
        let list = $(selector);
        arrayList = $.map(list, item => {
            return {
                elem: item,
                etop: $(item).offset().top,
                src: $(item).attr("data-src")
            }
        });
        load();
        $(window).on("scroll", load);
    }
    function load() {
        clearTimeout(timer);
        timer = setTimeout(() => {
            let scrollT = $(window).scrollTop();
            let minHeight = scrollT + clientHeight;
            
            $.each(arrayList, (index,item) => {
                if (item.etop < minHeight) {
                    item.elem.src = item.src;
                }
            })
            // timer = null;
        }, 100);

    }
    return lazyLoad;

})